using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace SwaggerDemo.Core;

/// <summary>
/// 给Swagger添加全局Header参数
/// </summary>
public class SwaggerFilter : IOperationFilter {
  void IOperationFilter.Apply (OpenApiOperation operation, OperationFilterContext context) {
    operation.Parameters.Add(new OpenApiParameter {
      Name = "x-lang",
      In = ParameterLocation.Header,
      Description = "多语言标识",
      Required = true,
      Schema = new OpenApiSchema {
        Type = "string",
        Default = new OpenApiString("zh-cn")
      }
    });
  }
}